//
//  DKMainSigleView.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/25.
//

#import "DKMainSigleView.h"
@interface DKMainSigleView()
@property (nonatomic, strong)UIImageView * dk_MainHeadImgView;
@property (nonatomic, strong)UILabel * dk_MainHeadLab;
@property (nonatomic, strong)UIButton * dk_MainGoBtn;
@property (nonatomic, strong)UILabel * dk_MainVersionLab;
@end
@implementation DKMainSigleView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = DK_Hex(@"#000000");
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_MainHeadImgView = [[UIImageView alloc] init];
    self.dk_MainHeadImgView.userInteractionEnabled = YES;
    [self addSubview:self.dk_MainHeadImgView];
    [self.dk_MainHeadImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(20)));
        make.width.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(30)));
        make.centerY.equalTo(self);
    }];
    self.dk_MainHeadLab = [[UILabel alloc] init];
    self.dk_MainHeadLab.textColor = DK_Hex(@"FFFFFF");
    self.dk_MainHeadLab.font = DK_FONT_Regular(11);
    [self addSubview:self.dk_MainHeadLab];
    [self.dk_MainHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_MainHeadImgView.mas_right).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(20)));
        make.centerY.equalTo(self.dk_MainHeadImgView);
    }];
    self.dk_MainGoBtn = [[UIButton alloc] init];
    [self.dk_MainGoBtn setBackgroundImage:DK_GetImage(@"dk_MainAlertGo") forState:UIControlStateNormal];
    [self.dk_MainGoBtn addTarget:self action:@selector(dk_MainGo) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.dk_MainGoBtn];
    [self.dk_MainGoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.height.equalTo(@(DK_IsWidthScale(16)));
        make.width.equalTo(@(DK_IsWidthScale(16)));
    }];
    self.dk_MainVersionLab = [[UILabel alloc] init];
    self.dk_MainVersionLab.textColor = DK_Hex(@"#999999");
    self.dk_MainVersionLab.font = DK_FONT_Regular(14);
    self.dk_MainVersionLab.hidden = YES;
    [self addSubview:self.dk_MainVersionLab];
    [self.dk_MainVersionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-DK_IsWidthScale(20)));
        make.height.equalTo(@(DK_IsWidthScale(20)));
        make.centerY.equalTo(self.dk_MainHeadLab);
    }];
}
- (void)dk_MainGo{
    if(self.goBlock){
        self.goBlock();
    }
}
-(void)setMainSigleALertType:(MainSigleALertType)mainSigleALertType{
    _mainSigleALertType = mainSigleALertType;
    if(_mainSigleALertType == MainSigleALertTypeFeedback){
        self.dk_MainHeadImgView.image = DK_GetImage(@"dk_MainAlertFeedback");
        self.dk_MainHeadLab.text = @"Feedback";
    }else if(_mainSigleALertType == MainSigleALertTypePwd){
        self.dk_MainHeadImgView.image = DK_GetImage(@"dk_MainAlertLock");
        self.dk_MainHeadLab.text = @"Change password";
    }else if(_mainSigleALertType == MainSigleALertTypeVersion){
        self.dk_MainVersionLab.hidden = NO;
        self.dk_MainGoBtn.hidden = YES;
        self.dk_MainHeadImgView.image = DK_GetImage(@"dk_MainAlertVersion");
        self.dk_MainHeadLab.text = @"Version number";
        
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        self.dk_MainVersionLab.text = app_Version;
    }
}
@end
